/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package oldShit;

import javax.swing.*;
import javax.swing.event.*;

/**
 *
 * @author tj
 */
public class ListPanel extends JPanel {

    private JList monthList;           // The months
    private JTextField selectedMonth;  // The selected month
    private JLabel label;              // A message
    private JScrollPane scrollPane;    // A scroll pane
    // The following array holds the values that will
    // be displayed in the monthList list component.
    private String[] months = {"January", "February",
        "March", "April", "May I fck u? LOLOLOL", "June", "July",
        "August", "September", "October", "November",
        "December"};

    public ListPanel() {

        monthList = new JList(months);

        // Set the selection mode to single selection.
        monthList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        // Register the list selection listener.
        monthList.addListSelectionListener(new ListListener());

        // Add the list to the panel.
        add(monthList);

        // Set the number of visible rows to 6.
        monthList.setVisibleRowCount(6);

        // Add the list to a scroll pane.
        scrollPane = new JScrollPane(monthList);

        // Add the scroll pane to the panel.
        add(scrollPane);

        // Create the label.
        label = new JLabel("You selected: ");

        // Create the text field.
        selectedMonth = new JTextField(10);

        // Make the text field uneditable.
        selectedMonth.setEditable(false);

        // Add the label and text field to the panel.
        add(label);
        add(selectedMonth);
    }

    private class ListListener implements ListSelectionListener {

        public void valueChanged(ListSelectionEvent e) {
            // Get the selected month.
            String selection =
                    (String) monthList.getSelectedValue();

            // Put the selected month in the text field.
            selectedMonth.setText(selection);
        }
    }
}
